package com.satchi.dao.imp;

import java.util.List;
import com.satchi.commons.BaseDao;
import com.satchi.dao.BalanceDao;
import com.satchi.hib.pojo.FinBalance;
import com.satchi.hib.pojo.FinCustomer;
import com.satchi.hib.pojo.FinUser;

public class GetBalanceDaoImp extends BaseDao implements BalanceDao {

	public int getCount() {
		String sql=" select * from FinBalance";
		int rows = getCount(sql);
		return rows;
	}

	public List getPageListNullPar(int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		String hql = "select fb.balanceId," +
		"fb.writeDate," +
		"fb.fitmentDate," +
		"fb.costProperty," +
		"fb.balancePrice," +
		"fb.shopArea," +
		"fb.finUser," +
		"fb.shopName," +
		"fb.finCustomer," +
		"fb.balanceRemark from FinBalance as fb order by balanceId";
		return getPageList(hql, pageNo, pageSize);
	}
	
	public List<FinBalance> getPageList(int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		String hql = "from FinBalance as fb order by balanceId";
		return getPageList(hql, pageNo, pageSize);
	}

	public List getPageListPar(Object[] params, int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		String hql  = "select fb.balanceId," +
		"fb.writeDate," +
		"fb.fitmentDate," +
		"fb.costProperty," +
		"fb.balancePrice," +
		"fb.shopArea," +
		"fb.finUser," +
		"fb.shopName," +
		"fb.finCustomer," +
		"fb.balanceRemark from FinBalance as fb ,FinCustomer as fc where " +
		" fb.finCustomer = fc.customerid" +
		" and writeDate between ? and ?" +
		" and fitmentDate between ? and ?" +
		" and fc.customer like ?" +
		" and costproperty =?  order by fb.balanceId";
		return getPageList(hql, params, pageNo, pageSize);
	}

	public List<FinUser> runResulthql(Object[] params) {
		// TODO Auto-generated method stub
		String hql = "from FinUser where uname=?";
		return runResultHql(hql,params);
	}

	public List<FinCustomer> runResulthqlCus(Object[] params) {
		// TODO Auto-generated method stub
		String hql = "from FinCustomer where customer=?";
		return runResultHql(hql,params);
	}
	
	
	
	public boolean save(FinBalance fb) {
		// TODO Auto-generated method stub
		return saveOrUpdate(fb);
	}

	public int getQueryCount(Object[] params) {
		String hql  = "select fb.balanceId," +
		"fb.writeDate," +
		"fb.fitmentDate," +
		"fb.costProperty," +
		"fb.balancePrice," +
		"fb.shopArea," +
		"fb.finUser," +
		"fb.shopName," +
		"fb.finCustomer," +
		" fb.balanceRemark from " +
		"FinBalance as fb ,FinCustomer as fc " +
		"where fb.finCustomer = fc.customerid" +
		" and writeDate between ? and ?" +
		" and fitmentDate between ? and ?" +
		" and fc.customer like ?" +
		" and costproperty =?  order by fb.balanceId";
		int rows = runResultHql(hql,params).size();
		return rows;
	}
}
